$.ajaxSetup ({cache: false});
/*
$.getScript('modules/jquery/xartemplates/includes/date.js');
$.getScript('modules/jquery/xartemplates/includes/jquery.dimensions.js');
$.getScript('modules/jquery/xartemplates/includes/jquery.bgiframe.js');
$.getScript('modules/jquery/xartemplates/includes/jquery.datePicker.js');

jQuery(document).ready(function(){jQuery('.date_due').datePicker();});
*/

var ajax_load = "<img class='loading' src='modules/reequipment/xarimages/ajax-loader.gif' alt='loading...' style='padding-left: 50px; padding-top: 50px;' />";
var update_load = "<img class='loading' src='modules/reequipment/xarimages/ajax-loader.gif' alt='loading...'  /> Updating...";
var finished = ' ';

function CompletePM(maintenance_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=ajax_complete&pageName=module';
    var newValue = $('#cycles_'+maintenance_id).val();
    $("#maintenance_"+maintenance_id).hide();
    $("#maintenance_form_updating").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
        loadUrl,
        $("#maintenance_form_"+maintenance_id).serialize()
        );
    $("#cycles").val(newValue);
}

function UpdatePM(maintenance_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=ajax_update&pageName=module';
    var newValue = $('#cycles_'+maintenance_id).val();
    $("#maintenance_form_updating").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
        loadUrl,
        $("#maintenance_form_"+maintenance_id).serialize()
        );
    $("#cycles").val(newValue);
}

function UpdateMaintenance(maintenance_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=ajax_update&pageName=module';
    var newValue = $('#cycles_'+maintenance_id).val();
    $("#maintenance_form_updating").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
        loadUrl,
        $("#maintenance_form_"+maintenance_id).serialize()
        );
    $("#cycles").val(newValue);
}

function CompleteMaintenance(maintenance_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=ajax_complete&pageName=module';
    var newValue = $('#cycles_'+maintenance_id).val();
    $("#maintenance_"+maintenance_id).hide();
    $("#maintenance_form_updating").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
        loadUrl,
        $("#maintenance_form_"+maintenance_id).serialize()
        );
    $("#cycles").val(newValue);
}

function CreateMaintenance(){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=ajax_create&pageName=module';
    $("#maintenance_form").fadeOut('Slow');
    $("#creating_maintenance").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
        loadUrl,
        $("#create_maintenance").serialize()
    );
    document.getElementById('create_maintenance').reset()
    $("#maintenance_form").fadeIn('Slow');
}

function ClickHereToPrint(){
    try{
        var oIframe = document.getElementById('ifrmPrint');
        var oContent = document.getElementById('printable').innerHTML;
        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document) oDoc = oDoc.document;
		oDoc.write("<html><head><title>Maintenance</title>");
		oDoc.write("<link type='text/css' rel='stylesheet' media='screen' href='themes/re/style/baseline.reset.css'>");
		oDoc.write("</head><body onload='this.focus(); this.print();'>");
		oDoc.write(oContent + "</body></html>");
		oDoc.close();
    }
    catch(e){
	    self.print();
    }
}